﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodonSegDP;
using System.Diagnostics;
using System.IO;
using AlgorithmResult;

namespace UnitTests
{
    class Program
    {
        static void Main(string[] args)
        {
            String testString =// "GAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGGGGGGGGCGCGCGCGCCGCGCGGCCCGCGCGCGCGCGCGCGCGCGGCCGCGCGCGCAGAGAGAGAGAGACCGCGCGCGCGCGCGCGCGCGCGGGGGGGGGGGGGGGGGAA";
                //  "GAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCT";
            "GAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTAGAAGCTGCAGTAGAAAAATTCGGTGTAGCTGCTGCTGCTGTTGCTGCCGCTGCTA";

    //        AnalyzeAndPrint(testString);



            string fn = @"C:\Users\Andrey\Downloads\na_whole-genome_genomic_dmel.FASTA";
            Console.WriteLine("Creating {0}", fn);
            // CreateBigFile(fn, 2000000000);
            Console.WriteLine("That is done...");
            int KByte = 1024;
            int MByte = KByte * 1024;
            char[] bytes = new char[MByte*1];
            char[] trimParams = new char[10];
            trimParams[0] = '\n';
            trimParams[1] = ' ';
            Stopwatch sw = new Stopwatch();
            sw.Start();

            FileStream fs = new FileStream(fn, FileMode.Open, FileAccess.Read);
            var reader = new StreamReader(fn);

            var line = reader.ReadLine();
            if (string.IsNullOrEmpty(line))
                return;

            long filelength = fs.Length;
            int readedSize = 0;
            if(line.StartsWith(">")){
                filelength -= line.Length;
            while (filelength > 0)
            {
                if (filelength < bytes.Length)
                {
                    readedSize=reader.Read(bytes, 0, (int)filelength);
                    AnalyzeAndPrint(new String(bytes).Trim(trimParams));//System.Text.Encoding.ASCII.GetString(bytes,0, (int)filelength));
                    break;
                }
                else
                {
                  
                    readedSize=reader.Read(bytes, 0, bytes.Length);
                    AnalyzeAndPrint(new String(bytes).Trim(trimParams));//System.Text.Encoding.ASCII.GetString(bytes));
                }
                filelength -= readedSize;
            }
            }
            Console.WriteLine("Time: {0} ms", sw.ElapsedMilliseconds);
            Console.ReadKey();
            fs.Close();
            reader.Close();
            
        }

        private static void AnalyzeAndPrint(String testString)
        {
            DynamicProgrammingAlg algorithm = new DynamicProgrammingAlg();
           
            Result algresult = algorithm.TripletBounderiesSegmentator(testString, 200);
            for (int i = 0; i < algresult.BoundariesSet.Length; i++) // Loop through array
            {
                if (algresult.BoundariesSet[i] != 0)
                    Console.WriteLine("bounderies indexes =" + algresult.BoundariesSet[i] + "  Arche Triplet " + algresult.ArchreTriplets[i]);
                else
                    break;

            }
        }
        


        

    }
}
